package com.goods.controller.business;

import com.goods.common.model.business.ProductCategory;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductCategoryTreeNodeVO;
import com.goods.common.vo.business.ProductCategoryVO;
import com.goods.common.vo.system.PageVO;
import com.goods.controller.business.service.ProductCategorySercice;
import io.swagger.annotations.Api;
import org.simpleframework.xml.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "物资类别")
@RestController
public class ProductCategoryController {

    @Autowired
    ProductCategorySercice productCategorySercice;

    /**
     * 展示分页列表
     * @param pageNum
     * @param pageSize
     * @param productCategoryVO
     * @return
     */
    @RequestMapping("business/productCategory/categoryTree")
    public ResponseBean findProductCategoryList(@RequestParam(required = false) Integer pageNum,
                                                @RequestParam(required = false) Integer pageSize,
                                                ProductCategoryVO productCategoryVO){
        PageVO<ProductCategoryTreeNodeVO> pageVOPageVOList = productCategorySercice.findProductCategoryList(pageNum,pageSize,productCategoryVO);
        return ResponseBean.success(pageVOPageVOList);
    }

    /**
     *父级分类
     * @return
     */
    @GetMapping("business/productCategory/getParentCategoryTree")
    public ResponseBean getParentCategoryTree(){
        List<ProductCategoryTreeNodeVO> parentTree =  productCategorySercice.getParentCategoryTree();
        return ResponseBean.success(parentTree);
    }

    /**
     * 添加商品类别
     * @param productCategoryVO
     * @return
     */
    @PostMapping("/business/productCategory/add")
    public ResponseBean add(@RequestBody ProductCategoryVO productCategoryVO){
        productCategorySercice.addProductCategory(productCategoryVO);
        return ResponseBean.success();
    }

    /**
     * 回显
     * @param id
     * @return
     */
    @GetMapping("/business/productCategory/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        ProductCategoryVO productCategoryVO = productCategorySercice.edit(id);
        return ResponseBean.success(productCategoryVO);
    }

    /**
     * 更新数据
     * @param productCategoryVO
     * @return
     */
    @PutMapping("/business/productCategory/update/{id}")
    public ResponseBean update(@RequestBody ProductCategoryVO productCategoryVO){
        productCategorySercice.update(productCategoryVO);
        return ResponseBean.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/business/productCategory/delete/{id}")
    public ResponseBean delete(@PathVariable Long id) throws Exception{
        productCategorySercice.delete(id);
        return ResponseBean.success();
    }

}
